import {
  find
} from '../../../../api/askfor';
const util = require('../../../../utils/util.js')
let app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    logisticsData: [],
    id: '',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.data.id = options.id
  },
  onShow: function () {
    this.findClick()
  },
  findClick() {
    var _this = this
    find(this.data.id).then(
      res => {
        if (res.type == 'success') {
          console.log(res)
          _this.data.logisticsData = res.data.askfor.itemList
          // for (var i = 0; i < _this.data.logisticsData.length; i++) {
          //   if (i == 0) {
          //     _this.data.logisticsData[i].spec1Reapet = '0';
          //   } else {
          //     if (_this.data.logisticsData[i].trackingNo == _this.data.logisticsData[i - 1].trackingNo) {
          //       _this.data.logisticsData[i].spec1Reapet = '1';
          //     } else {
          //       _this.data.logisticsData[i].spec1Reapet = '0';
          //     }
          //   }
          // }
          console.log(_this.data.logisticsData)
          _this.data.logisticsData.forEach(function(item) {
            item.createDate = util.datetimeFormat(item.createDate)
          })
          _this.setData({
            logisticsData: _this.data.logisticsData
          })
        }
      }
    ).catch(error => {
      console.log(error)
    })
  },
  detailsClick(data) {
    console.log(data)
    if (!util.isNull(data.currentTarget.dataset.trackingno)) {
      wx.navigateTo({
        url: '/pages/order/jumpPage/order/logisticsDetails?trackimgno=' + data.currentTarget.dataset.trackingno,
      })
    } else {
      wx.showToast({
              icon: "none",
        title: '暂无物流信息',
      })
    }
  }
})